package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author feihao
 * @version 1.0
 * @date 2021/6/29 20:43
 */

@Service
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    public UserInfo queryTodayBestInfo(Long id) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", id);
        return userInfoMapper.selectOne(queryWrapper);
    }


    public List<UserInfo> queryRecommendationUserInfo(QueryWrapper<UserInfo> queryWrapper) {
        return userInfoMapper.selectList(queryWrapper);
    }

    public List<UserInfo> queryUserInfoByUserIdList(List<Object> ids) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("user_id", ids);
        return this.queryRecommendationUserInfo(queryWrapper);
    }


    /**
     * 跟新用户信息：
     *
     * @param userInfo
     * @return
     */
    public Boolean updateUserInfo(UserInfo userInfo) {

        UpdateWrapper<UserInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id", userInfo.getUserId());
        int update = userInfoMapper.update(userInfo, updateWrapper);
        return update > 0;
    }
}
